package org.darkforest.common.sms;
import java.util.Arrays;

public class SendMsg {
	 
	/**
	 * 
	 * @param phone 手机号
	 * @param msg 短信内容
	 * @param type 短信类型 0-->应用；1-->营销
	 * @return
	 */
	public static int sendMsg(String phone, String msg, int type){
		String url = "";
		String account = "";
		String password = "";
		String needstatus = PropertiesUtils.getPara("needstatus");
		boolean nsb = false;
		if(needstatus == null || needstatus == ""){
			return -1;
		}else {
			if("0".equals(needstatus))
				nsb = true;
			else if("1".equals(needstatus))
				nsb = false;
		}
		if(type == 0){
			url = PropertiesUtils.getPara("app_url");
			if(url == null || url == "")
				return -1;
			account = PropertiesUtils.getPara("app_account");
			if(account == null || account == "")
				return -2;
			password = PropertiesUtils.getPara("app_password");
			if(password == null || password == "")
				return -3;
		}else {
			url = PropertiesUtils.getPara("market_url");
			if(url == null || url == "")
				return -1;
			account = PropertiesUtils.getPara("market_account");
			if(account == null || account == "")
				return -2;
			password = PropertiesUtils.getPara("market_password");
			if(password == null || password == "")
				return -3;
		}
		String product = null;// 产品ID
		String extno = null;// 扩展码
		String rss="";
		try {
			rss = HttpSender.batchSend(url, account, password, phone, msg,
					nsb, product, extno);
		} catch (Exception e) {
			e.printStackTrace();
		}
		String[] arr = rss.split(",");
		System.out.println(Arrays.toString(arr));
		return Integer.parseInt(arr[1].trim());
	}
}
